﻿using PHRClient.DoctorForms;
using PHRClient.PatientForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PHRClient
{
    public partial class PHRDetails : Form
    {
        public static Dashboard _dashboard = null;
        public static ImagesData _imagesData = null;
        public static AddDetails _addDetails = null;
        public static PatientDetails _history = null;

        public PHRDetails()
        {
            InitializeComponent();

            List<PatientData> productsread = PatientDataCollection.Load(PatientDataLoader.XMLFILE);

            _history = new PatientDetails();
            _history.Show();

            this.TopLevel = false;
            this.AutoScroll = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Dock = DockStyle.Fill;

            if (DoctorMainForm._mainForm.InvokeRequired)
            {
                DoctorMainForm._mainForm.BeginInvoke((MethodInvoker)delegate()
                {
                    DoctorMainForm._mainForm.Controls.Clear();
                    DoctorMainForm._mainForm.Controls.Add(this);
                });
            }
            else
            {
                DoctorMainForm._mainForm.Controls.Clear();
                DoctorMainForm._mainForm.Controls.Add(this);
            }

            MainForm.PortListnerStop();
        }

        public PHRDetails(Patient patient)
        {
            InitializeComponent();

            List<PatientData> productsread = PatientDataCollection.Load(PatientDataLoader.XMLFILE);

            _history = new PatientDetails();
            _history.Show();

            this.TopLevel = false;
            this.AutoScroll = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Dock = DockStyle.Fill;

            this.pName.Text = patient.Name;
            this.pTel.Text = patient.Tel;
            this.pAddress.Text = patient.Address;

            this.pAge.Text = patient.Age;
            this.pBirthday.Text = patient.Birthday;

            this.pHeightCm.Text = patient.HeightCm;
            this.pHeightInch.Text = patient.HeightInch;

            this.pWeightKg.Text = patient.WeightKg;
            this.pWeightLb.Text = patient.WeightLb;

            if(patient.Gender.Equals("Male"))
                this.pSexPicBox.Image = global::PHRClient.Properties.Resources.male;
            else if(patient.Gender.Equals("Female"))
                this.pSexPicBox.Image = global::PHRClient.Properties.Resources.female;

            try
            {
                string appPath = Path.GetDirectoryName(Application.ExecutablePath);
                string profPic = @appPath + "\\Data\\patient" + patient.PatientId + ".jpg";

                if (File.Exists(profPic))
                {
                    this.profPicBox.Image = Image.FromFile(profPic);
                }
                else this.profPicBox.Image = global::PHRClient.Properties.Resources.photo;
            }
            catch (Exception)
            {
                this.profPicBox.Image = global::PHRClient.Properties.Resources.photo;
            }
           

            if (DoctorMainForm._mainForm.InvokeRequired)
            {
                DoctorMainForm._mainForm.BeginInvoke((MethodInvoker)delegate()
                {
                    DoctorMainForm._mainForm.Controls.Clear();
                    DoctorMainForm._mainForm.Controls.Add(this);
                });
            }
            else
            {
                DoctorMainForm._mainForm.Controls.Clear();
                DoctorMainForm._mainForm.Controls.Add(this);
            }

            MainForm.PortListnerStop();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
            MainForm._loginForm = new LoginForm();
            MainForm._loginForm.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _dashboard = new Dashboard();
            _dashboard.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _imagesData = new ImagesData();
            _imagesData.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            _addDetails = new AddDetails();
            _addDetails.Show();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            _history = new PatientDetails();
            _history.Show();
        }
    }
}
